package org.example.leetcode;


import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * @version 1.0.0
 * @author: lynn
 * @description:
 * @date: 2021/8/9 16:41
 */
public class LC58 {


    public static void main(String[] args) {
        String str="luffy is still joyboy";
        LC58 lc=new LC58();
        int count=lc.lengthOfLastWord(str);
        System.out.println(count);
    }

    public int lengthOfLastWord(String s) {
        StringBuilder sb=new StringBuilder();
        for (int j = s.length()-1; j >=0 ; j--) {
            if (s.charAt(j)!=' '){
                sb.append(s.charAt(j));
            }
            if (sb.length()>0 && s.charAt(j)==' '){
                break;
            }
        }
        return sb.length();
    }
}
